Skip to content

fix(decorator): do not cache error responses (#575) - #2

Merged
agustin18 merged 4 commits into
stablefrom
fix/575-error-response
Nov 13, 2026
Merged

agustin18 merged 4 commits into
stablefrom
fix/575-error-response

Conversation

@agustin18

@agustin18 agustin18 commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Do not cache Response objects with status codes >= 400.
  • Add a regression test covering 404 and 500 responses.
  • Add the changelog fragment and update the migration/compatibility status.

Motivation

A cached error Response could be returned as HTTP 200 on a later request. This is the first behavior fix in the fork and is intentionally scoped to upstream long2ice#554/long2ice#575. Credit to RitiGrover for the upstream fix.

Behavior change

Error responses (status >= 400) returned explicitly as Response objects are delivered directly and are not stored in the cache. Successful responses keep the existing behavior.

Scope

This fix covers explicitly returned Response objects with status >= 400. It does not cover every FastAPI error mechanism, such as mutating the status code of an injected Response; those cases need separate tests and PRs.

Tests

  • RED reproduced on stable d47e66b before the fix: assert 200 == 404 for the second request.
  • GREEN after the fix: 404/404 and 500/500; the endpoint counter increments on every request.
  • pytest -q: 30 passed, 4 xfailed (strict; P0-05).
  • diff-cover: 100% on the two changed runtime lines.
  • Ruff, pre-commit, mypy on changed files, build, twine check, artifact inspection: passed.
  • Wheel smoke install: 404 n=1, 404 n=2 from the installed package.

Compatibility

  • No public API change.
  • Intentional behavior fix documented in MIGRATION.md and COMPATIBILITY.md.
  • Old cached error entries may remain until their TTL expires. Flush the cache namespace if you were affected.

Migration notes

See the “Error responses” row in MIGRATION.md. No code changes are required.

Changelog

changelog.d/2.bugfix.md links to this PR in the generated changelog. The upstream credit to RitiGrover remains in the fragment text.

Checklist

  • Tests added/updated
  • Changelog fragment
  • Docs updated
  • No secrets
  • Backward compatibility reviewed
  • No unrelated runtime changes

CI and tooling note

Two small CI/tooling fixes were required to make this PR checks green. They are isolated in separate commits and do not change runtime behavior:

  • The typecheck job now checks only changed Python files with a minimal mypy config. The inherited strict config follows imports into modules with pre-existing errors; restoring a strict baseline is tracked as technical debt.
  • The Towncrier workflow now uses Towncrier 26 because 22.12 imports pkg_resources, which current setuptools no longer exposes. The dev dependency is restricted to Python >=3.9.

These are prerequisites for the changed-files gate and the changelog check. If preferred, they can be split into a separate tooling PR before merge.

Related

Return Response objects with status >= 400 directly instead of encoding and caching them. A cached 404 could be served as HTTP 200 on a later request.

Add a regression test for 404 and 500 responses, the changelog fragment, and update the migration/compatibility status.
Check only changed Python files with a minimal mypy config. The inherited strict config follows imports into modules with pre-existing errors; the full baseline is a follow-up.
@agustin18 agustin18 added bug Something isn't working compatibility Compatibility contract and migration labels Nov 13, 2026
Towncrier 22.12 imports pkg_resources, which current setuptools no longer exposes. Use towncrier 26 in the workflow and lockfile; the dev dependency is restricted to Python >=3.9.
Rename the fragment from 554 to 2 so Towncrier links to the fork PR instead of a non-existent fork issue. Keep the upstream credit in the fragment text.
@agustin18
agustin18 merged commit 4e77bc4 into stable Nov 13, 2026
12 checks passed
@agustin18
agustin18 deleted the fix/575-error-response branch November 13, 2026 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working compatibility Compatibility contract and migration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant